<template>
    <div class="comment-sex">
      <!-- 导航栏 -->
      <van-picker
        title="性别修改"
        show-toolbar
        :columns="columns"
        @confirm="onConfirm"
        @cancel="$emit('close')"
        :default-index="value"
        @change="OnchangeS"
        />
  
      <!-- 输入框 -->
=
    </div>
  </template>
  
  <script>
  import {updateUserProfile} from '@/api/user'
  export default {
      name:'CommentSex',
      props:{
          value:{
              type:Number,
              required:true
          }
      },
      data() {
          return {
              columns:['男','女'],
              localGender:this.value
  
          }
      },
      methods:{
        async onConfirm(){
            this.$toast.loading({
                message:'保存中...',
                forbidClick:true, //禁止背景点击
                duration:0 //持续展示
            })
            try{
                await updateUserProfile({
                    gender:this.localGender
                })
                //更新视图
                this.$emit('input',this.localGender)
                //关闭弹层
                this.$emit('close')
                //提示成功
                this.$toast.success('更新性别成功')
            }catch(err){
                this.$toast('更新性别失败')
            }
        },
        OnchangeS(picker,value,index){
            this.localGender = index

        }
      }
  }
  </script>
  
  <style lang="less" scoped>
      
  </style>